package javachongkao.编程基础.求平均数;

import java.util.Scanner;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        ArrayList<Double> numbers = new ArrayList<>();

        System.out.println("输入数字计算平均数（输入非数字结束）:");

        while (scanner.hasNextDouble()) {
            numbers.add(scanner.nextDouble());
        }

        if (numbers.isEmpty()) {
            System.out.println("未输入有效数字");
        } else {
            double sum = 0;
            for (double num : numbers) {
                sum += num;
            }
            double average = sum / numbers.size();
            System.out.printf("平均数: %.2f\n", average);
        }

        scanner.close();
    }
}
